/**
 * 
 */
package com.hospital.proxy;

import java.util.List;

import com.hospital.dao.INewsDao;
import com.hospital.dao.impl.NewsDaoImpl;
import com.hospital.dbc.DatabaseConnection;
import com.hospital.vo.News;

/**
 * @author Administrator
 *
 */
public class NewsDaoProxy implements INewsDao {
	INewsDao dao = null;
	DatabaseConnection dbc = null;
	public NewsDaoProxy() {
		try {
			this.dbc = new DatabaseConnection();
		} catch (Exception e) {
			e.printStackTrace();
		}
		this.dao = new NewsDaoImpl(this.dbc.getConnection());
	}
	/* (non-Javadoc)
	 * @see com.hospital.dao.INewsDao#doCreate(com.hospital.vo.News)
	 */
	@Override
	public boolean doCreate(News news) throws Exception {
		boolean flag = false;
		try {
			flag = this.dao.doCreate(news);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return flag;
	}
	@Override
	public List<News> findByType(String keyWord, String type,int startIndex, int count) throws Exception {
		List<News> list = null;
		try {
			list = this.dao.findByType(keyWord, type,startIndex, count);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return list;
	}
	@Override
	public boolean doUpdate(News news) throws Exception {
		boolean flag = false;
		try {
			flag = this.dao.doUpdate(news);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return flag;
	}
	@Override
	public int count(String type) throws Exception {
		int count = 0;
		try {
			count = this.dao.count(type);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return count;
	}
	@Override
	public News findById(int nid) throws Exception {
		News news = null;
		try {
			news = this.dao.findById(nid);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return news;
	}
	@Override
	public boolean doDel(int nid) throws Exception {
		boolean flag = false;
		try {
			flag = this.dao.doDel(nid);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return flag;
	}
	@Override
	public boolean doUpdateT(News news) throws Exception {
		boolean flag = false;
		try {
			flag = this.dao.doUpdateT(news);
		} catch (Exception e) {
			throw e; 
		} finally {
			this.dbc.close();
		}
		return flag;
	}
	@Override
	public List<News> findReferences(int nid, String type, int size) throws Exception {
		List<News> list = null;
		try {
			list = this.dao.findReferences(nid, type, size);
		} catch (Exception e) {
			throw e;
		} finally {
			this.dbc.close();
		}
		return list;
	}

}
